﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace h1
{
    public partial class Form_resetPassword : Form
    {
        string select;
        public Form_resetPassword()
        {
            InitializeComponent();
        }

        public Form_resetPassword(string select)
        {
            InitializeComponent();
            this.select = select;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox2.Text == "")
            {
                errorProvider1.SetError(textBox2, "请重新设置密码！");
            }
            else if(textBox1.Text == "")
            {
                errorProvider1.SetError(textBox1, "请再次输入密码！");
            }
            else if(textBox2.Text != textBox1.Text)
            {
                errorProvider1.SetError(textBox1, "密码不一致！");
            }
            else
            {
                try
                {
                    DataSet ds = MySqlHelper.getDataSet(MySqlHelper.Conn, "SELECT * FROM users");
                    DataRow[] rows = ds.Tables[0].Select(select);
                    rows[0].BeginEdit();
                    rows[0]["userPassword"] = textBox2.Text;
                    rows[0].EndEdit();
                    MySqlHelper.updateDataSet(MySqlHelper.Conn, "SELECT * FROM users", ds);
                    Form_message form_Message = new Form_message("密码修改成功！","密码修改成功，请重新尝试登陆！");
                    form_Message.ShowDialog();
                    this.Close();
                }catch(Exception ex)
                {
                    Form_message form_Message = new Form_message("密码修改错误！", "错误描述：" + ex.Message);
                    form_Message.ShowDialog();
                }
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (button5.Text=="🔒")
            {
                button5.Text = "🔑";
                textBox2.UseSystemPasswordChar = false;
            }
            else
            {
                button5.Text = "🔒";
                textBox2.UseSystemPasswordChar = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (button2.Text == "🔒")
            {
                button2.Text = "🔑";
                textBox1.UseSystemPasswordChar = false;
            }
            else
            {
                button2.Text = "🔒";
                textBox1.UseSystemPasswordChar = true;
            }
        }
    }
}
